package comgutianyu.qihangjiaoyu.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import comgutianyu.qihangjiaoyu.R;
import comgutianyu.qihangjiaoyu.model.Course;

public class CourseAdapter extends RecyclerView.Adapter<CourseAdapter.CourseViewHolder> {
    private List<Course> courses;

    public CourseAdapter(List<Course> courses) {
        this.courses = courses;
    }

    @NonNull
    @Override
    public CourseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_course, parent, false);
        return new CourseViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull CourseViewHolder holder, int position) {
        Course course = courses.get(position);
        holder.tvCourseTitle.setText(course.getTitle());
        holder.tvTeacherName.setText(course.getTeacherName());
        holder.ivTeacherAvatar.setImageResource(course.getTeacherAvatar());
    }

    @Override
    public int getItemCount() {
        return courses.size();
    }

    static class CourseViewHolder extends RecyclerView.ViewHolder {
        TextView tvCourseTitle;
        TextView tvTeacherName;
        ImageView ivTeacherAvatar;
        Button btnContinueStudy;

        public CourseViewHolder(@NonNull View itemView) {
            super(itemView);
            tvCourseTitle = itemView.findViewById(R.id.tvCourseTitle);
            tvTeacherName = itemView.findViewById(R.id.tvTeacherName);
            ivTeacherAvatar = itemView.findViewById(R.id.ivTeacherAvatar);
            btnContinueStudy = itemView.findViewById(R.id.btnContinueStudy);
        }
    }
} 